home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PGP5GUI - A GUI using Magic User Interface v3.8
- **
- ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
- **
- ** This source code is released as FREEWARE - Use it for whatever you like,
- ** as long as NO financial reward is gained by you for such usage.
- **
- ** If you use any parts of the this source code for anything, give ME credit
- ** wherever credit is due, please ;-)
- */
-
- /*
- ** Functions to handle the interface between PGPE and the GUI
- */
-
- /* Library stuff */
- #include <libraries/mui.h>
- #include <dos/dostags.h>
-
- /* Prototypes */
- #ifdef __GNUC__
- #include <clib/muimaster_protos.h>
- #include <proto/alib.h>
- #endif
-
- #include <proto/muimaster.h>
- #include <proto/exec.h>
- #include <clib/alib_protos.h>
- #include <clib/alib_stdio_protos.h>
- #include <proto/dos.h>
-
- /* Ansi */
- #include <string.h>
-
- /* Include generated by GenCodeC */
- #include "PGP5GUI.h"
-
- char *pgp5_tmp = "T:pgp5.tmp";
- char *pgp5_tmp_asc = "T:pgp5.tmp.asc";
-
- char *armor_on_str = "+armor=on";
- char *armor_off_str = "+armor=off";
-
- char *txmode_on_str = " +textmode=on";
- char *txmode_off_str = " +textmode=off";
-
- extern char *enc_mode, *enc_options, *enc_files;
- extern char *encclippath, *encclipfile, *encclipfilename;
- extern char *exec_buff;
-
- extern char *keyidsbuff;
- extern char *keyselection[];
-
- extern int SelectPGPKey(struct ObjApp *app, char *sel[], char *title, ULONG multiselect);
- extern BOOL GetSaveASLFileName(struct ObjApp *app, char *hail, char *pathbuff, char *filebuff, char *tofile);
-
- extern void PGP5_Execute(UBYTE *command, struct ObjApp *app);
- extern LONG GetCycle(Object *obj);
-
- extern BOOL ReadClipToFile(char *tmp, struct ObjApp *app);
- extern BOOL WriteFileToClip(char *tmp, struct ObjApp *app);
-
- /*
- ** Do the Encryption
- ** PGPE -r <recipient> [-s [-u <myid>]] [-aftz] [-o <outfile>] file ...
- ** PGPE -c [-aftz] [-o outfile] file ...
- */
- BOOL
- Do_Encryption(struct ObjApp *App)
- {
- char tofile[512];
-
- /* Title for the file requester */
- char title[] = "Save Encrypted Clip To (.asc) Text File...";
-
- char *encfilesbuff = "\0";
-
- int err = 0, i;
-
- /* Values for the Cycle gadgets on the Encryption page */
- LONG Enc_MODE, Enc_USEARMOR, Enc_TEXTMODE, clipmode;
-
- clipmode = GetCycle(App->CY_Encrypt_CLIP);
-
- *encclipfilename = '\0';
-
- switch (clipmode)
- {
- case 3: /* Encrypt from clip to clip */
- if (ReadClipToFile(pgp5_tmp, App))
- {
- encfilesbuff = pgp5_tmp;
- }
-
- break;
-
- case 2: /* Encrypt from clip to file */
- if (ReadClipToFile(pgp5_tmp, App))
- {
- encfilesbuff = pgp5_tmp;
-
- /* Get name of file to save encrypted clip to... */
- if (GetSaveASLFileName(App, title, encclippath, encclipfile, tofile))
- {
- /* Build up the command line to send to DOS */
- sprintf(encclipfilename, " +force -o \"%s\"", tofile);
- }
- else
- {
- /* Force exit */
- encfilesbuff = "\0";
- }
- }
-
- break;
-
- case 1: /* Encrypt from file to clip */
- get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&encfilesbuff);
-
- /* If we have a file name, then do the encryption */
- if (*encfilesbuff)
- {
- if (WriteFileToClip(encfilesbuff, App))
- {
- if (ReadClipToFile(pgp5_tmp, App))
- {
- encfilesbuff = pgp5_tmp;
- }
- else
- {
- /* Force exit */
- encfilesbuff = "\0";
- }
- }
- else
- {
- /* Force exit */
- encfilesbuff = "\0";
- }
- }
-
- break;
-
- default: /* Encrypt from file to default (file) */
- get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&encfilesbuff);
- break;
- }
-
- /* If we have a file name, then do the encryption */
- if (*encfilesbuff)
- {
- strcpy(enc_files, encfilesbuff);
-
- /* Get mode of encryption */
- Enc_MODE = GetCycle(App->CY_Encrypt_MODE);
-
- /* Using clipboard? */
- if (clipmode)
- {
- /* We lock these modes for clipboard use! */
- Enc_USEARMOR = TRUE;
- Enc_TEXTMODE = TRUE;
- }
- else
- {
- /* Get the values of the cycle gadgets */
- Enc_USEARMOR = GetCycle(App->CY_Encrypt_USEARMOR);
- Enc_TEXTMODE = GetCycle(App->CY_Encrypt_TEXTMODE);
- }
-
- if (Enc_USEARMOR)
- {
- /* Use ASCII armor */
- strcpy(enc_options, armor_on_str);
- }
- else
- {
- /* Don't use ASCII armor */
- strcpy(enc_options, armor_off_str);
- }
-
- if (Enc_TEXTMODE)
- {
- /* Do universal compatible text mode */
- strcat(enc_options, txmode_on_str);
- }
- else
- {
- /* Don't do universal compatible text mode */
- strcat(enc_options, txmode_off_str);
- }
-
- /* Specify public-key encryption */
- *enc_mode = '\0';
-
- switch (Enc_MODE)
- {
- case 2:
- /* Specify conventional encryption */
- strcpy(enc_mode,"-c");
- *keyidsbuff = '\0';
- break;
-
- case 1:
- /* Specify public-key encryption and signing */
- strcpy(enc_mode,"-s");
-
- /* FALL-THROUGH */
-
- case 0:
- /* Get list of recipients */
- err = SelectPGPKey(App, keyselection, "Select Recipient(s)...",
- MUIV_Listview_MultiSelect_Default);
-
- if (!err)
- {
- if (*keyselection[0])
- {
- strcpy(keyidsbuff, "-r ");
- strcat(keyidsbuff, keyselection[0]);
-
- for(i = 1; i < 256; i++)
- {
- if (*keyselection[i] != NULL)
- {
- strcat(keyidsbuff, " -r ");
- strcat(keyidsbuff, keyselection[i]);
- }
- else
- {
- break;
- }
- }
- }
- }
-
- break;
-
- default:
- break;
- }
-
- if (!err)
- {
- /* Build up the command line to send to DOS */
- sprintf(exec_buff, "PGPE %s %s %s %s \"%s\"",
- keyidsbuff, enc_mode, enc_options, encclipfilename, enc_files);
-
- /* Send the command to DOS */
- PGP5_Execute(exec_buff, App);
-
- /* Are we using the clipboard? */
- if (clipmode)
- {
- /* clipmode not equal to 'clip to file'? */
- if (clipmode != 2)
- {
- /*
- ** Encrypt from file/clip to clip...
- ** Copy encrypted temporary file (T:pgp5.tmp.asc) to clip
- */
- WriteFileToClip(pgp5_tmp_asc, App);
- }
-
- /*
- ** Encrypt from file/clip to clip...
- ** Delete encrypted temporary file (T:pgp5.tmp.asc, etc.)
- */
- DeleteFile(pgp5_tmp_asc);
- DeleteFile(pgp5_tmp);
- }
- }
- else
- {
- if (err != -1)
- return(FALSE); /* Couldn't get MUI App opened */
- }
- }
-
- return(TRUE);
- }
-